package _chujisuanfa;
import java.util.*;
public class _06 {
    public static void main(String[] args) {
        int[] nums1=new int[]{1,2,2,1};
        int[] nums2=new int[]{2,2};
        System.out.println(Arrays.toString(intersect(nums1, nums2)));
    }
    /**
     * @param nums1
     * @param nums2
     * @return
     */
    public static int[] intersect(int[] nums1, int[] nums2) {
        int n1=nums1.length;
        int n2 = nums2.length;
        int n3=Math.max(n1,n2);
        HashSet hc=new HashSet();
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        HashSet hs=new HashSet();
        for(int i=0;i<n1;i++){
            hs.add(nums1[i]);
        }
        for(int i=0;i<n2;i++){
            if(hs.contains(nums2[i])){
                hc.add(nums2[i]);
            }
        }
        int c=hc.size();
        int[] b = new int[c];
        int e=0;
        Iterator it = hc.iterator();
        while(it.hasNext()){
            b[e++]=(int) it.next();
        }
        return b;
    }
}
